﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE GetSiteMapPath 
	@catId int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @t table
	(
		CategoryId int,
		Title varchar(255), 
		Parent int
	)
	declare @parent int
	set @parent = @catId
	while (select count(*) from Categories where CategoryId = @parent) > 0
	begin
		insert into @t (CategoryId, Title, Parent) 
		select CategoryId, Title, Parent from Categories
		where CategoryId = @parent
		select @parent = Parent from @t where CategoryId = @parent
	end;
	select * from @t
END


